const path = require('path');
const HomeRouter = require(path.join(__dirname,"HomeRouter"));
const UserRouter = require(path.join(__dirname,"UserRouter"));
const ClassRouter = require(path.join(__dirname,"ClassRouter"));
const SchoolRouter = require(path.join(__dirname,"SchoolRouter"));
const ProjectRouter = require(path.join(__dirname,"ProjectRouter"));
const StudentRouter = require(path.join(__dirname,"StudentRouter"));
const TeacherRouter = require(path.join(__dirname,"TeacherRouter"));
const WeeklyRouter=require(path.join(__dirname,"WeeklyRouter"));
const ScoreRouter=require(path.join(__dirname,"ScoreRouter"));



function Router(app)
{
  //主路由
  app.get('/',function(req,res){

      if(req.url == '/home/login' || req.url == '/home/logout')
      {
          next();  //跳过
      }else{
          if(!req.session.user_name)  //没有登录就跳转到登录界面
          {
              //重定向
              res.redirect(`/home/login`);
          }
      }

      // res.redirect('/home/index');
  });

  //后台首页路由
  app.use('/home',HomeRouter);

  //账号路由
  app.use('/user',UserRouter);

  app.use('/classs',ClassRouter);

  app.use('/school',SchoolRouter);

  app.use('/student',StudentRouter);

  app.use('/project',ProjectRouter);

  app.use('/teacher',TeacherRouter);

  app.use('/weekly',WeeklyRouter);

  app.use('/score',ScoreRouter);

}


module.exports = Router;